package com.ashlikun.keeplive.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import com.ashlikun.keeplive.AlarmManageHelp
import com.ashlikun.keeplive.KeepLive
import com.ashlikun.keeplive.service.JobHandlerService
import com.ashlikun.keeplive.utils.ServiceUtils


/**
 * 作者　　: 李坤
 * 创建时间: 2024/9/30　16:15
 * 邮箱　　：496546144@qq.com
 *
 * 功能介绍：
 */
class CheckServiceReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent?) {
        KeepLive.loge("CheckServiceReceiver onReceive: Checking service status")
        //再次启动AlarmManageHelp
        AlarmManageHelp.get().startAlarmManager()
//
//        if (!ServiceUtils.isServiceRunning(context, JobHandlerService::class.java.name)) {
//            //启动定时器，在定时器中启动本地服务和守护进程
//            val intent = Intent(context, JobHandlerService::class.java)
//            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//                context.startForegroundService(intent)
//            } else {
//                context.startService(intent)
//            }
//        }
        if (!KeepLive.isStart) {
            KeepLive.loge("CheckServiceReceiver onReceive: startWork")
            KeepLive.startService()
        }
    }
}